<?php

namespace App\Models;

use App\Models\Traits\ActiveUserHelperTrait;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;
    use ActiveUserHelperTrait;

    protected $appends = [
        'userAvatar'
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','avatar_path',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function avatar()
    {
        if ($this->avatar_path) {
            $file_path = $this->avatar_path;
        } else {
            $file_path = 'avatars/default.jpg';
        }
        return asset('storage/'.$file_path);
    }

    public function getUserAvatarAttribute()
    {
        return $this->avatar();
    }
}
